<?php

class Rute extends CI_Model {

    function index() {
        $q = $this->db->get('rute');
        return $q->result();
    }

    function show($id) {
        $this->db->where('id', $id);
        $q = $this->db->get('admin_bank');
        return $q;
    }

    function edit($id) {
        $this->db->where('id', $id);
        $q = $this->db->get('rute');
        return $q->result();
    }

    function create($from, $to, $date) {
        $data1 = array(
            'from' => $from,
            'to' => $to,
            'date' => $date,
        );
        $data2 = array(
            'from' => $to,
            'to' => $from,
            'date' => $date,
        );
        $this->db->insert('rute', $data1);
        $this->db->insert('rute', $data2);
        redirect('rutes/index');
    }

    function update($id, $from, $to) {
         $data = array(
            'from' => $from,
            'to' => $to,
        );
        $this->db->where('id', $id);
        $this->db->update('rute', $data);
        redirect('rutes/index');
    }

    function delete($id) {
        $this->db->where('id', $id);
        $this->db->delete('rute');
        redirect('rutes/index');
    }
    
     public function record_count() {
        return $this->db->count_all("rute");
    }
    
    function fetch_costumer($limit, $start) {
        $this->db->order_by('id', 'DESC');
        $this->db->limit($limit, $start);
        $query = $this->db->get("rute");
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
    }
    
    
    function get_array() {
        $this->db->order_by('nama', 'ASC');
        $q = $this->db->get('airport');
        foreach ($q->result_array() as $row) {
            $data{$row['code']} = $row['nama'] . ' ('.$row['code'].')';
        }
        return $data;
    }
    
    function get_airport($code){
        $this->db->where('code', $code);
        $q = $this->db->get('airport');
        foreach($q->result() as $airport){
            $data = $airport->nama;
        }
        return $data;
    }

}

?>
